package com.net.xpay.common.manager.impl.partner;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.net.common.annotation.ReadTransactional;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractVersionedManager;
import com.net.noah.core.service.SerialNumberService;
import com.net.xpay.common.dao.partner.PartnerWithdrawRecordBatchMapper;
import com.net.xpay.common.domain.partner.PartnerWithdrawRecordBatch;
import com.net.xpay.common.manager.partner.PartnerWithdrawRecordBatchManager;
import com.net.xpay.common.model.search.PartnerWithdrawRecordBatchSearchModel;
import com.net.xpay.core.constant.TransBizTypeConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
@ReadTransactional
public class PartnerWithdrawRecordBatchManagerImpl extends AbstractVersionedManager<PartnerWithdrawRecordBatch> implements PartnerWithdrawRecordBatchManager{

    @Autowired
    private PartnerWithdrawRecordBatchMapper mapper;

    @Autowired
    private SerialNumberService serialNumberService;

    @Override
    public int save(PartnerWithdrawRecordBatch obj) {
        Preconditions.checkArgument(obj.getId() == null);
        obj.setId(serialNumberService.getLongSerialNumber(getTableFullName()));
        //业务号
        obj.setBizId(TransBizTypeConstant.PW + obj.getId());
        return super.save(obj);
    }


    @Override
    protected BasicMapper<Long, PartnerWithdrawRecordBatch> getMapper() {
        return mapper;
    }

    @Override
    public List<PartnerWithdrawRecordBatch> search(PartnerWithdrawRecordBatchSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(PartnerWithdrawRecordBatchSearchModel searchModel) {
        return mapper.searchCount(searchModel);
    }

    @Override
    public PartnerWithdrawRecordBatch findByBizId(String bizId) {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(bizId));
        PartnerWithdrawRecordBatch condition = new PartnerWithdrawRecordBatch();
        condition.setBizId(bizId);
        return getByCondition(condition);
    }
}
